@extends('adminDialog')
@section('content')
<form action="{{url('admin/item/update/'.$type.'/'.$model->id)}}" method="POST" class="J_ajaxForm">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <div class="pop_cont pop_table" style="overflow-y: scroll;height: 529px;">
            <table width="100%">
                <tbody>
                @foreach(config('site.items.'.$type.'.data') as $key=>$item)
                    <tr>
                        <th>
                            <label for="title">
                                {{$item['name']}}
                                @if(strstr($item['attribute'],'request'))<span class="red">*</span>@endif
                            </label>
                        </th>
                        <td>
                            @if("input" == $item['type'])
                                <input type="text" name="{{$key}}" id="{{$key}}" class="input length_6"  value="{{isset($data[$key]) ? $data[$key] :""}}"/>
                            @elseif("textarea" == $item['type'])
                                <textarea name="{{$key}}" id="{{$key}}" style="width:350px; height: 100px;">{{isset($data[$key]) ? $data[$key] :""}}</textarea>
                            @elseif("img" == $item['type'])
                                <a href="javascript:;" id="pickfiles" class="pickfiles" title="选择上传文件">
                                    <input type="hidden" name="{{$key}}" value="{{isset($data[$key]) ? $data[$key] :""}}"/>
                                    <img data-picSize="{{$item['value']}}" src="/img/{{$type}}-{{isset($data[$key]) ? $data[$key] :""}}/{{$item['value']}}" onerror="this.src='{{url("images/defaltPic.jpg")}}'"/>
                                </a>
                            @elseif("select" == $item['type'])
                                <select name="{{$key}}">
                                    @foreach($item['value'] as $valueKey=>$value)
                                    <option value="{{$valueKey}}" @if(isset($data[$key]) && $data[$key] == $valueKey) selected="selected"@endif>{{$value}}</option>
                                    @endforeach
                                </select>
                            @elseif('UEdit' == $item['type'])
                                <script id="container" name="{{$key}}" type="text/plain">
                                    {!!isset($data[$key]) ? $data[$key] :"" !!}
                                </script>

                            @elseif("dynamicSelect" == $item['type'])
                                <select name="{{$key}}">
                                    @foreach($navs[$item['value']]['data'] as $valueKey=>$value)
                                        <option value="{{json_decode($value)->id}}" @if(isset($data[$key]) && $data[$key] == json_decode($value)->id) selected="selected"@endif>{{json_decode($value)->name}}</option>
                                    @endforeach
                                </select>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
    </div>

    <div class="pop_bottom cc">
        <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
        <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
    </div>
</form>
@stop

@section('style')
    <style>
        .body_none {
            width: 720px;
        }
    </style>
@stop

@section('js')
    @parent
    @include('UEditor::head')
    <script src="{{ asset('js/plupload/plupload.full.min.js') }}"></script>
    <script>
        var ue = UE.getEditor('container', {
            initialFrameWidth: 600, initialFrameHeight: 300, autoHeightEnabled: false, toolbars: [
                ['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc'],
                ['link', 'simpleupload', 'insertimage']
            ]
        });
        ue.ready(function () {
            ue.execCommand('serverparam', '_token', "{{ csrf_token() }}");//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
        });
    </script>
    <script>
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'pickfiles', // you can pass in id...
                //container: document.getElementById('container'), // ... or DOM Element itself
                url: "{{ url('upimg') }}",
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ]
                },
                multi_selection: false,
                file_data_name: 'file',
                multipart_params: {'_token': '{{ csrf_token() }}', 'dir': '{{$type}}'},
                // Flash settings
                flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
                // Silverlight settings
                silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
                init: {
                    PostInit: function () {
                        return false;
                    },
                    FilesAdded: function (up, file) {
                        $('.up-pic img').attr('src', '{{ asset('images/loading.gif') }}');
                        uploader.start();
                    },
                    Error: function (up, err) {
                        tips(err.message);
                    },
                    FileUploaded: function (up, file, responseObj) {
                        var response = $.parseJSON(responseObj.response);
                        if (response.state == 'success') {
                            __type = "{{$type}}";
                            $('.pickfiles img').attr('src', '{!! url("img/'+__type+'-' + response.id + '/290-165") !!}');
                            $('.pickfiles input').val(response.id);
                        } else {
                            tips(response.message);
                        }
                    }
                }
            });
            uploader.init();
        });
    </script>
@stop
